package com.yuntongxun.ecdemo.voicechat.ui.activity;

import android.content.Intent;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.yuntongxun.ecdemo.R;
import com.yuntongxun.ecdemo.voicechat.bean.PostResult;
import com.yuntongxun.ecdemo.voicechat.comman.EventBusTags;

import butterknife.InjectView;
import butterknife.OnClick;

/**
 * 选择支付方式
 *
 * @author li_zhuonan
 * @version 1.0
 * @since 2016/11/21
 */

public class PaymentActivity extends BaseChatActivity {
//    @Override
//    protected boolean isBindEventBusHere() {
//        return false;
//    }
//
//    @Override
//    protected int getContentViewLayoutID() {
//        return 0;
//    }
//
//    @Override
//    protected void initViewsAndEvents() {
//
//    }

    public static final String PAY_COINS="pay_coins";
    private String coins="";

    @InjectView(R.id.alipay_cb)
    CheckBox alipayCb;
    @InjectView(R.id.wechat_cb)
    CheckBox wechatCb;
    @InjectView(R.id.paypal_cb)
    CheckBox paypalCb;


    @Override
    protected boolean isBindEventBusHere() {
        return true;
    }

    public void onEvent(PostResult postResult){
        if (EventBusTags.PAY_SUCCESS.equals(postResult.getTag())){
            finish();
        }
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_payment;
    }

    @Override
    protected void initViewsAndEvents() {
        coins=getIntent().getStringExtra(PAY_COINS);
        setTitle("Payment");
        alipayCb.setChecked(true);

        alipayCb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                if (isChecked){
                    wechatCb.setChecked(false);
                    paypalCb.setChecked(false);
                }


            }
        });

        wechatCb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    alipayCb.setChecked(false);
                    paypalCb.setChecked(false);
                }
            }
        });

        paypalCb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    alipayCb.setChecked(false);
                    wechatCb.setChecked(false);
                }
            }
        });
    }
    String type="";
    @OnClick(R.id.next_btn)
    public void onNextClick(){
        if (coins.equals("")){
            return;
        }
        if (!alipayCb.isChecked()&&!wechatCb.isChecked()&&!paypalCb.isChecked()){
            showToastLong("Please select");
            return;
        }

        if (alipayCb.isChecked()){
            type=PaymentConfirmActivity.ALIPAY;
        }

        if (wechatCb.isChecked()){
            type=PaymentConfirmActivity.WECHAT;
        }

        if (paypalCb.isChecked()){
            type=PaymentConfirmActivity.PAYPAL;
        }

        Intent intent=new Intent(this, PaymentConfirmActivity.class);
        intent.putExtra(PaymentConfirmActivity.PAY_COINS,coins);
        intent.putExtra(PaymentConfirmActivity.PAY_TYPE,type);
        startActivity(intent);

    }

}
